﻿@inject Microsoft.AspNetCore.Hosting.IWebHostEnvironment HostingEnvironment
@{
    Layout = "~/Views/Shared/" + ViewBag.Layout + ".cshtml";

    ShowSelfModel user = ViewBag.CurrentUser;
    var userAvatarUrl = Url.Content("~/images/avatar.png");
    if (user != null)
    {
        if (!user.ThumbnailPostfix.IsNullOrEmpty())
        {
            var fileName = "thumbnail" + user.ThumbnailPostfix; ;
            userAvatarUrl = Url.Content("~/File/GetImage/Attachment/UserThumbnail/" + user.ActorId) + "?fileName=" + (fileName) + "&random=" + new Random().Next();
        }
    }

    ShowTenantDto tenant = ViewBag.CurrentTenant;
    bool tenantIsNull = tenant == null;
    string tenantShortName ="Undefiled";
    string tenantIcoUrl = "/favicon.ico";
    string tenantThumbnailUrl = "/images/no-thumbnail.png";
    string tenantImageUrl = "/images/no-image.png";
    if (!tenantIsNull)
    {
        if (tenant.Id == "0")
        {
            tenantThumbnailUrl = "/images/tenant/logo.png";
            tenantImageUrl = "/images/tenant/trademark.png";
            tenantIcoUrl = "/images/tenant/ico.ico";
        }
        else
        {
            if (!tenant.ThumbnailPostfix.IsNullOrEmpty())
            {
                var fileName = "image" + tenant.ThumbnailPostfix;
                tenantThumbnailUrl = Url.Content("~/File/GetImage/Attachment/TenantThumbnail/" + tenant.Id) + "?fileName=" + (fileName) + "&random=" + new Random().Next();
            }
            if (!tenant.ImagePostfix.IsNullOrEmpty())
            {
                var fileName = "image" + tenant.ImagePostfix;
                tenantImageUrl = Url.Content("~/File/GetImage/Attachment/TenantImage/" + tenant.Id) + "?fileName=" + (fileName) + "&random=" + new Random().Next();
            }
            if (tenant.HasIco == 1)
            {
                var fileName = "ico.ico";
                tenantIcoUrl = Url.Content("~/File/GetImage/Attachment/TenantIco/" + tenant.Id) + "?fileName=" + (fileName) + "&random=" + new Random().Next();
            }
        }
        tenantShortName = tenant.ShortName;
    }

    ConfigItem portal = ViewBag.CurrentPortal;
    bool portalIsNull = portal == null;
    string portalId = portalIsNull ? "Undefined" : portal.Id.ToString();
    string portalAbbr = portalIsNull ? "Undefined" : portal.Attribute2;
    string portalName = portalIsNull ? "Undefined" : portal.Name;
    string portalDes = !portalIsNull ? (portal.Description.IsNullOrEmpty() ? "Undefined" : portal.Description) : "null";
    ViewBag.Title = portalName + "-" + tenantShortName;
    ViewBag.Keywords = portalName;
    ViewBag.Description = portalDes;
    ViewBag.TenantIcoUrl = tenantIcoUrl;
    string landingPageUrl = ViewBag.LandingPageUrl;
    string topMenuItemId = ViewBag.TopMenuItemId;
}

@BundlerHelper.Render(HostingEnvironment.ContentRootPath, Url.Content("~/app/portal-data.min.js"))

<div id="wrapper">
    <!--左侧导航开始-->
    <nav class="navbar-default navbar-static-side" role="navigation">
        <div class="nav-close">
            <i class="fa fa-times-circle"></i>
        </div>
        <div class="sidebar-collapse">
            <ul class="nav" id="side-menu">
                <li id="tenant" class="logo" style="padding-left:9px">
                    <div class="image-left">
                        <img alt="image" src='@tenantThumbnailUrl' class="img-circle" height="32" width="32" />
                    </div>
                    <div class="block" style="padding-left: 42px; margin-top: 2px;text-align: left; ">
                        <span class="block">@tenantShortName</span>
                    </div>
                </li>
                <li id="nav-header">
                    <div style="padding-top:10px">
                    </div>
                </li>
                @{
                    List<ListMenuItemsDto> menuItemList = ViewBag.MenuItems;
                    foreach (var menuItem in menuItemList.Where(x => x.ParentId == topMenuItemId))
                    {
                        <li data-type="menu">
                            @if (menuItem.Type == (int)MenuItemType.Directory) //dir:
                            {
                                if (menuItemList.Where(x => x.ParentId == menuItem.Id).Count() != 0)//dir: has child
                                {
                                    <a href="#">
                                        <i class="@menuItem.Icon"></i>
                                        <span class="nav-label">@menuItem.Name</span>
                                        <span class="fa arrow"></span>
                                    </a>
                                }

                            }
                            else
                            {
                                if (menuItem.Type == (int)MenuItemType.OuterLink)
                                {
                                    <a href='@(menuItem.Url)' target='_blank'>@menuItem.Name</a>
                                }
                                else if (menuItem.IsBlankTarget)
                                {
                                    <a class="menu-item-a" data-url='@Url.Content("~/" + menuItem.Url)' target='_blank'>@menuItem.Name</a>
                                }
                                else
                                {
                                    <a class="menu-item-b" href="#" data-url='@Url.Content("~/" + menuItem.Url)'>@menuItem.Name</a>
                                }


                            }
                            <ul class="nav nav-second-level collapse" data-type="menu">
                                @foreach (var secondLevelMenuItem in menuItemList.Where(x => x.ParentId == menuItem.Id).OrderBy(x => x.Sequence))
                                {
                                    <li data-type="menu">

                                        @if (secondLevelMenuItem.Type != (int)MenuItemType.Directory)
                                        {
                                            if (secondLevelMenuItem.Type == (int)MenuItemType.OuterLink)
                                            {
                                                <a href='@(secondLevelMenuItem.Url)' target='_blank'>@secondLevelMenuItem.Name</a>
                                            }
                                            else if (secondLevelMenuItem.IsBlankTarget)
                                            {
                                                <a class="menu-item-a" data-url='@Url.Content("~/" + secondLevelMenuItem.Url)' target='_blank'>@secondLevelMenuItem.Name</a>
                                            }
                                            else
                                            {
                                                <a class="menu-item-b" href="#" data-url='@Url.Content("~/" + secondLevelMenuItem.Url)'>@secondLevelMenuItem.Name</a>
                                            }

                                        }
                                        else if (menuItemList.Where(x => x.ParentId == secondLevelMenuItem.Id).Count() == 0)//dir: no children
                                        {
                                            <a href="#"><span class="nav-label">@secondLevelMenuItem.Name</span></a>
                                        }
                                        else  //dir: has children
                                        {
                                            <a href="#">
                                                <i class="@secondLevelMenuItem.Icon"></i>
                                                <span class="nav-label">@secondLevelMenuItem.Name</span>
                                                <span class="fa arrow"></span>
                                            </a>
                                            <ul class="nav nav-third-level" data-type="menu">
                                                @foreach (var thirdLevelMenuItem in menuItemList.Where(x => x.ParentId == secondLevelMenuItem.Id & x.Type != (int)MenuItemType.Directory).OrderBy(x => x.Sequence))
                                                {
                                                    <li data-type="menu">
                                                        @if (thirdLevelMenuItem.Type == (int)MenuItemType.OuterLink)
                                                        {
                                                            <a href='@(thirdLevelMenuItem.Url)' target='_blank'>@thirdLevelMenuItem.Name</a>
                                                        }
                                                        else if (thirdLevelMenuItem.IsBlankTarget)
                                                        {
                                                            <a class="menu-item-a" data-url='@Url.Content("~/" + thirdLevelMenuItem.Url)' target='_blank'>@thirdLevelMenuItem.Name</a>
                                                        }
                                                        else
                                                        {
                                                            <a class="menu-item-b" href="#" data-url='@Url.Content("~/" + thirdLevelMenuItem.Url)'>@thirdLevelMenuItem.Name</a>
                                                        }

                                                    </li>
                                                }
                                            </ul>
                                        }

                                    </li>
                                }
                            </ul>
                        </li>
                    }
                }
            </ul>
        </div>
    </nav>
    <!--左侧导航结束-->
    <!--右侧部分开始-->
    <div id="page-wrapper" class="gray-bg dashbard-1">
        <div class="row">
            <nav class="navbar navbar-static-top" role="navigation" style="margin-bottom: 0">
                <a class="navbar-minimalize minimalize-styl-2" href="#" title="收起菜单">
                    <i class="fa fa-bars"></i>
                </a>
                <span style="color:#fff;font-size:14px;font-weight: 600">@portalName-@portalDes</span>
                <ul class="nav navbar-top-links navbar-right welcome-message">
                    <li><a id="fullScreen"><i class="fa fa-arrows-alt"></i>全屏</a></li>
                    <li class="dropdown user-menu">
                        <a href="javascript:void(0)" class="dropdown-toggle" data-hover="dropdown">
                            <img src="@userAvatarUrl" class="user-image">
                            <span class="hidden-xs">@user.Name</span>
                        </a>
                        <ul class="dropdown-menu">
                            <li class="mt5">
                                <a class="menu-item-b" href="#" data-url='@Url.Content("~/Sys/User/ManageSelf")'>
                                    <i class="fa fa-male"></i> 个人中心
                                </a>
                            </li>
                            <li>
                                <a onclick="showUploadThumbnailModal()">
                                    <i class="fa fa-user"></i> 上传头像
                                </a>
                            </li>
                            <li>
                                <a onclick="showChangePasswordModal()">
                                    <i class="fa fa-key"></i> 修改密码
                                </a>
                            </li>
                            <li>
                                <a onclick="showChangeSkinModal()">
                                    <i class="fa fa-dashboard"></i> 切换主题
                                </a>
                            </li>
                            <li class="divider"></li>
                            <li>
                                <a href="#" onclick="loginOff()">
                                    <i class="fa fa-sign-out"></i> 退出登录
                                </a>
                            </li>
                        </ul>
                    </li>
                </ul>
            </nav>
        </div>
        <div class="row content-tabs">
            <button class="roll-nav roll-left tabLeft">
                <i class="fa fa-backward"></i>
            </button>
            <nav class="page-tabs menuTabs">
                <div class="page-tabs-content">
                    <a href="javascript:;" class="active menuTab" data-id="/system/main">首页</a>
                </div>
            </nav>
            <button class="roll-nav roll-right tabRight">
                <i class="fa fa-forward"></i>
            </button>
            <div class="btn-group roll-nav roll-right">
                <button class="dropdown J_tabClose" data-toggle="dropdown">
                    页签操作<span class="caret"></span>
                </button>
                <ul role="menu" class="dropdown-menu dropdown-menu-right">
                    <li><a class="tabCloseCurrent" href="#">关闭当前</a></li>
                    <li><a class="tabCloseOther" href="#">关闭其他</a></li>
                    <li><a class="tabCloseAll" href="#">全部关闭</a></li>
                </ul>
            </div>
            <a href="#" class="roll-nav roll-right tabReload"><i class="fa fa-refresh"></i> 刷新</a>
        </div>
        <div class="row mainContent" id="content-main">
            <iframe class="YiSha_iframe" name="iframe0" width="100%" height="100%" data-id="/system/main" src="@Url.Content(ViewBag.LandingPageUrl)" frameborder="0" seamless></iframe>
        </div>
    </div>
    <!--右侧部分结束-->
</div>

<script type="text/javascript">
    if (!ys.isNullOrEmpty($.cookie('Skin'))) {
        var skin = decodeURIComponent($.cookie('Skin'));
        $("body").addClass(skin.split('|')[0]);
        $("body").addClass(skin.split('|')[1]);
    } else {
        var sideTheme = "theme-dark";
        var skinName = "skin-blue";
        $("body").addClass(sideTheme);
        $("body").addClass(skinName);
    }
    setIndexPortal();

    $(function () {

    });

    function setIndexPortal() {
        var portal = {};
        portal.Id = '@portalId';
        portal.ClientType = '@((int)ClientType.MvcAdmin)';
        setPortal(portal);
        initPortalData();
    }


    function showUploadThumbnailModal() {
        ys.openDialog({
            title: "上传头像",
            height: '580px',
            btn: ['关闭'],
            content: '@Url.Content("~/Sys/User/UploadSelfAttachmentModal")' + '?index=squarethumbnail',
            callback: function (index, layero) {
                //location.reload();
                var frame = window[layero.find('iframe')[0]['name']];
                frame.LeaveForm(index);
            }
        });
    }

    function showChangePasswordModal() {
        ys.openDialog({
            title: "修改密码",
            height: "320px",
            content: '@Url.Content("~/Sys/User/ChangeSelfPasswordModal")',
            callback: function (index, layero) {
                var frame = window[layero.find('iframe')[0]['name']];
                frame.saveForm(index);
            }
        });
    }

    function showChangeSkinModal() {
        ys.openDialog({
            title: "换肤",
            height: "460px",
            btn:['关闭'],
            content: '@Url.Content("~/Home/Skin")',
            callback: function (index, layero) {
                var frame = window[layero.find('iframe')[0]['name']];
                frame.LeaveForm(index);
            }
        });
    }


    function loginOff() {
         ys.ajax({
                url: '@Url.Content("~/Sys/User/Logoff")',
                type: "post",
                success: function (rst) {
                    if (rst.Flag == 1) {
                       location.href = '@Url.Content("~/Sys/User/Logon?portal="+ portalAbbr)';
                    }
                    else {
                        ys.msgError(rst.Message);
                    }
                }
            });
    }

    function reloadLocation() {
        location.reload();
    }

</script>
